[跪求]java一个复数Complex由两部分组成......

来源:百度知道 编辑:UC知道 时间:2024/05/06 08:34:04
(java)
一个复数Complex由两部分组成:实部realPart和虚部imaginaryPart,两个复数可进行加,减,乘,除四则运算.试设计一个带有四则运算的复数类.并编写程序演示该类算法.

谢谢.谢谢

http://zhidao.baidu.com/question/5407748.html?si=1
http://zhidao.baidu.com/question/17541398.html?si=3

public class Complex
{
private double realPart;
private double imaginaryPart;

public Complex(double a, double b)
{
this.realPart = a;
this.imaginaryPart = b;
}

public Complex add(Complex a)
{
Complex result = new Complex(this.realPart + a.realPart, this.imaginaryPart + a.imaginaryPart);//(why?)
return result;
}

public Complex decrease(Complex a)
{
Complex result = new Complex(this.realPart - a.realPart, this.imaginaryPart - a.imaginaryPart);//(why?)
return result;
}

public Complex multiply(Complex a)
{
double